﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using RestEntities;

namespace WcfRestLib
{
	public static class MyRestUriTemplate
	{
		public const string Person = "/Person/{id}";
		public const string JsonPerson = "json/Person/{id}";

		public const string Persons = "/Persons";
		public const string JsonPersons = "/json/Persons";

		public const string CreatePerson = "/Admin/Person";
		public const string CreateJsonPerson = "/json/Admin/Person";
		public const string AdminPerson = "/Admin/Person/{pid}";
		public const string PersonById = "/PersonById/{id}";
		public const string PersonByName = "/PersonByName/{name}";

		public const string Comment = "/Comment/{cid}";
		public const string PersonCommentsByName = "/PersonCommentsByName/{name}";
		public const string PersonCommentsById = "/PersonCommentsById/{id}";
		public const string CreateComment = "/Admin/{pid}/Comment";
		public const string AdminComment = "/Admin/Comment/{cid}";
	}


	[ServiceContract(Name = "IRestService")]
	public interface IRestService
	{
		[WebGet(UriTemplate = MyRestUriTemplate.Persons, ResponseFormat = WebMessageFormat.Xml)]
		[OperationContract]
		List<Person> GetAllPersons();

		[WebGet(UriTemplate = MyRestUriTemplate.JsonPersons,
			ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
		[OperationContract]
		List<Person> GetAllPersonsJson();

		[OperationContract]
		[WebGet(UriTemplate = MyRestUriTemplate.PersonById, ResponseFormat = WebMessageFormat.Xml)]
		Person GetPersonById(string id);

		[OperationContract]
		[WebGet(UriTemplate = MyRestUriTemplate.JsonPerson,
			ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
		Person GetPersonJson(string id);

		[OperationContract]
		[WebGet(UriTemplate = MyRestUriTemplate.PersonByName, ResponseFormat = WebMessageFormat.Xml)]
		List<Person> GetPersonByName(string name);

		[OperationContract]
		[WebInvoke(Method = "POST", UriTemplate = MyRestUriTemplate.CreatePerson, RequestFormat = WebMessageFormat.Xml
			, ResponseFormat = WebMessageFormat.Xml)]
		void CreatePerson(Person person);

		[OperationContract]
		[WebInvoke(Method = "POST", UriTemplate = MyRestUriTemplate.CreateJsonPerson, RequestFormat = WebMessageFormat.Json
			, ResponseFormat = WebMessageFormat.Json)]
		void CreateJsonPerson(Person person);

		[OperationContract]
		[WebInvoke(Method = "PUT", UriTemplate = MyRestUriTemplate.AdminPerson,
			RequestFormat = WebMessageFormat.Xml)]
		void UpdatePerson(string pid, Person person);

		[OperationContract]
		[WebInvoke(Method = "DELETE", UriTemplate = MyRestUriTemplate.AdminPerson,
			RequestFormat = WebMessageFormat.Xml)]
		void DeletePerson(string pid);



		[OperationContract]
		[WebGet(UriTemplate = MyRestUriTemplate.PersonCommentsById, ResponseFormat = WebMessageFormat.Xml)]
		List<Comment> GetUserCommentsById(string id);

		[OperationContract(Name = "GetUserCommentsByName")]
		[WebGet(UriTemplate = MyRestUriTemplate.PersonCommentsByName, ResponseFormat = WebMessageFormat.Xml)]
		List<Comment> GetUserCommentsByName(string name);

		[OperationContract]
		[WebInvoke(Method = "POST", UriTemplate = MyRestUriTemplate.CreateComment,
			ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
		void CreateComment(string pid, Comment comment);


		[OperationContract]
		[WebInvoke(Method = "PUT", UriTemplate = MyRestUriTemplate.AdminComment,
			ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
		void UpdateComment(string cid, Comment comment);


		[OperationContract]
		[WebInvoke(Method = "DELETE", UriTemplate = MyRestUriTemplate.AdminComment,
			ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
		void DeleteComment(string cid);

	}
}
